﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//import
using Microsoft.Practices.Unity;
using System.Web.ModelBinding;
using ddcCajamarca.BusinessLogic.AgendaCultural.Service;
using System.IO;
using ddcCajamarca.BusinessEntities.AgendaCultural;

namespace ddcCajamarca.Web.AgendaCultural
{
    public partial class frmAmbiente : System.Web.UI.Page
    {
       
        [Dependency]
        public IAmbienteBL ambientedBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var accion = Request.QueryString["accion"];
            var id = Request.QueryString["id"];
            if (accion != null && accion == "nuevo")
            {
                fvAmbiente.DefaultMode = FormViewMode.Insert;
            }
            else if (accion != null && id != null && accion == "delete")
            {
                Int32 idAmbiente = Int32.Parse(id);

                
            }
        }

        public Ambiente GetAmbiente([QueryString("id")] Int32? id)
        {
            if (id.HasValue)
                return ambientedBL.GetFromAmbienteById(id.Value);
            return null;
        }

        public void UpdateAmbiente(Ambiente ambiente)
        {

            if (ModelState.IsValid)
                ambientedBL.UpdateAmbiente(ambiente);
            Response.Redirect("~/AgendaCultural/frmListAmbientes.aspx");
        }

        public void InsertAmbiente(Ambiente ambiente)
        {
            if (ModelState.IsValid)
            {
                ambientedBL.AddAmbiente(ambiente);
            }
            Response.Redirect("~/AgendaCultural/frmListAmbientes.aspx");

        }
    }
}